define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
		this.callParent();
	};

	

	

	

	Model.prototype.bindBtnClick = function(event){
	    var me = this;
	    var userName = me.comp("username").val();
	    var password = me.comp("password").val();
	    var openId = me.getParentModel().user.openId;
	    var data = {};
	    data.loginName = userName;
	    data.password = password;
	    if(me.getParentModel().user.accountType == 'WX'){
	    	data.openId = openId;
	    }else if(me.getParentModel().user.accountType == 'QQ'){
	        data.qqId = openId;
	    }
	    
	    if(userName && password){
	    	var url = 'http://www.xjzlhy.com:81/ex_community/a/api/community/alreadyAccountBind?callback=?';
	        $.getJSON(url,
	                  data,
	                  function(data){
	                      
	                	  if(data.errNo != -1){
	                	       
							   localStorage.setItem("userInfo",JSON.stringify(data));
							   if(data.data[0].userType == '4'){
								   $('.MerchantMall').show();
							   }	
						       $(".rollText").text(data.data[1].name + "欢迎您，祝心想事成，万事如意！");  
						      
						       justep.Shell.showPage("main");
						       if(me.getParentModel().comp('body').getActiveIndex() == 3){
						    	   me.getParentModel().comp('mineContainer').setSrc('$UI/communityOto/mine/mineFragment.w');
						    	   me.getParentModel().comp('mineContainer').refresh();
						       }else{
						    	   me.getParentModel().comp("contentDialog").open({src:me.getParentModel().toPath});
						       }
						       justep.Util.hint("绑定成功",{delay:1000,position:"middle"});
						      // location.reload(true);
						      
						   }else{
							  justep.Util.hint("用户名或密码错误",{
						    		type:"danger"
						    	}); 
						   }
	                  });
		    }else{
		    	justep.Util.hint("用户名或密码不能为空",{
	    		type:"danger"
	    	});
		    }
		
	};

	

	Model.prototype.bindNewUserClick = function(event){
		this.owner.setSrc('$UI/communityOto/mine/bindNewUser.w');
		this.owner.refresh();
		
	};

	

	Model.prototype.backBtnClick = function(event){
	
		this.getParentModel().goBackLogin();

	};

	

	return Model;
});